package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 使用预编译SQL完成UPDATE语句
 */
public class JDBCDemo8 {
    public static void main(String[] args) {
        //需求:根据id修改用户的信息
        try (Connection connection = DBUtil.getConnection();){
            String sql = "UPDATE userinfo " +
                         "SET username=?,password=?,nickname=?,age=? " +
                         "WHERE id=?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,"张三");
            ps.setString(2,"789987");
            ps.setString(3,"阿三");
            ps.setInt(4,60);
            ps.setInt(5,2);
            int num = ps.executeUpdate();
            if(num>0){
                System.out.println("修改成功");
            }else{
                System.out.println("修改失败");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}






